<template>
  <div class="order-detail-page" v-if="order">
    <!-- 操作栏 -->
    <DetailAction :order="order"/>
    <!-- 步骤条 -->
    <DetailSteps :order="order" />
    <!-- 物流栏 -->
    <Suspense>
      <!-- 组件加载完毕 -->
      <template #default>
        <DetailLogistics v-if="[3, 4, 5].includes(order.orderState)" :order="order" @on-logistics="handlerLogistics"/>
      </template>
      <!-- 组件加载中显示 -->
      <template #fallback>
        <div class="loading">loading...</div>
      </template>
    </Suspense>
    <!-- 订单商品信息 -->
    <DetailInfo :order="order"/>
    <OrderLogistics ref="orderLogisticsCom" />
  </div>
</template>

<script>
import DetailAction from './components/detail-action.vue'
import DetailSteps from './components/detail-steps.vue'
import DetailLogistics from './components/detail-logistics.vue'
import OrderLogistics from './components/order-logistics.vue'
import DetailInfo from './components/detail-info.vue'
import {ref} from 'vue'
import {findOrderDetail} from '@/api/order'
import {useRoute} from 'vue-router'
export default {
  name:'OrderDetailPage',
  components: {DetailAction, DetailSteps, DetailLogistics,OrderLogistics,DetailInfo},
  setup() {
    const order = ref(null)
    const route = useRoute()
    findOrderDetail(route.params.id).then(data => {
      order.value = data.result
    })
    return {order,...useLogistics()}
  }
}
// 查看物流逻辑
export const useLogistics = () => {
  const orderLogisticsCom = ref(null)
  const handlerLogistics = (order) => {
    orderLogisticsCom.value.open(order)
  }
  return {handlerLogistics,orderLogisticsCom}
}
</script>

<style lang="less" scoped>
.order-detail-page{
  background: #fff;
  height: 100%;
}
.loading {
  height: 50px;
  display: flex;
  align-items: center;
  padding: 0 30px;
  background-color: #f5f5f5;
  margin: 30px 50px 0;
}
</style>